home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / ams__l~1.zoo / include / joystick.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-05  |  1.6 KB  |  71 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of the Atari Machine Specific Library,
  4. //  and is Copyright 1992 by Warwick W. Allison.
  5. //
  6. //  You are free to copy and modify these sources, provided you acknowledge
  7. //  the origin by retaining this notice, and adhere to the conditions
  8. //  described in the file COPYING.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef _Joystick_h
  13. #define _Joystick_h
  14. //
  15. //  Support for direct Joystick access.
  16. //
  17. #include <bool.h>
  18.  
  19. enum JoystickDirection {    J_0, J_U, J_D, J_UD, J_L, J_UL, J_DL, J_UDL,
  20.                             J_R, J_UR, J_DR, J_UDR, J_LR, J_ULR, J_DLR, J_UDLR };
  21.  
  22. class Joystick
  23. {
  24. public:
  25.     Joystick(int port=1);
  26.     ~Joystick();
  27.  
  28.     JoystickDirection Way();
  29.  
  30.     bool Passive();
  31.     bool Up();
  32.     bool Down();
  33.     bool Left();
  34.     bool Right();
  35.  
  36.     // NOTE: Trigger 1 only works if joystick 0 is being used,
  37.     //       otherwise it is diverted as RightButton of the mouse.
  38.     //      (Blame Atari)
  39.     //
  40.     bool Trigger();
  41.  
  42.     // -1, 0, or +1 interpretation of joystick
  43.     int X();
  44.     int Y();
  45.  
  46. private:
  47.     volatile int (*Flags);
  48.     short port;
  49. };
  50.  
  51.  
  52. // Below is private
  53.  
  54.  
  55. inline JoystickDirection Joystick::Way() { return *Flags&J_UDLR; }
  56.  
  57. inline bool Joystick::Passive() { return !*Flags; }
  58. inline bool Joystick::Up() { return !!(*Flags&J_U); }
  59. inline bool Joystick::Down() { return !!(*Flags&J_D); }
  60. inline bool Joystick::Left() { return !!(*Flags&J_L); }
  61. inline bool Joystick::Right() { return !!(*Flags&J_R); }
  62.  
  63. extern int XDif[16];
  64. extern int YDif[16];
  65.  
  66. inline int Joystick::X() { return XDif[Way()]; }
  67. inline int Joystick::Y() { return YDif[Way()]; }
  68.  
  69.  
  70. #endif
  71.